package Recursive;

public class huanghou8 {
    int max=8;
    int[] arr = new int[max];
    static int count=0;
    public static void main(String[] args) {
        huanghou8 n  = new huanghou8();
        n.check(0);
        System.out.println(count);
    }
    public void check(int n){
        //判断是否为max
        if(n==max){
            print();
            return;
        }
        for(int i =0;i<arr.length;i++){
            arr[n]=i;
            if(judeg(n)){
                check(n+1);
            }
        }
    }
    //判断是否冲突
    public boolean judeg(int n){
        for (int j = 0; j < n; j++) {
            if(Math.abs(arr[n]-arr[j])==Math.abs(n-j)||arr[j]==arr[n]){
                return false;
            }
        }
        return true;
        }

    //写一个打印，打印八皇后位置
    public void print(){
        count++;
        for (int a:arr) {
            System.out.print(a+"-");
        }
        System.out.println();
    }
}
